// import CreateRemindertip from "./ReminderTip";

import {
  newSessionid,
  getCatesian3FromPX,
  createRemindertip,
  destroyTip,
} from "../../plotCommon";
import imageIcon from "/public/svg/billboard/default.png";
import CreateCircle from "./CreateCircle";
import EditElliptic from "./EditCircle";
import { ElMessage } from "element-plus";
const Cesium = window.Cesium;

export default class Circle {
  handler: any;
  _viewer: any;
  _option:any
  _entities: Array<any>;
  editCircle: any;
  pickerEntity: any;
  constructor(viewer: any) {
    this._viewer = viewer;
    this._entities = [];
  }
  get options() {
    return this._option;
  }
  set options(val) {
    val = Object.assign({}, val);
    this._option = val;

  }
  get entities() {
    return this._entities;
  }
  set entities(val) {
    this._entities = val;
  }
  create() {
    let viewer = this._viewer;
    this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    const resultList:any = [];
    const callback = (event:any) => {
      console.log(event, "event");
      this._entities.push(event);
    };
    CreateCircle(viewer, this.handler, resultList, this._option, callback);
  }
  stopCreate() {
    if (this.handler) this.handler.destroy();
  }
  //目前没用
  edit(editCalback:any) {
    this.stopCreate();
    let viewer = this._viewer;
    this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    const calback = (e:any) => {
      if (editCalback && typeof editCalback == "function") editCalback(e);
      this.editCircle = EditElliptic(e, this.handler, []);
    };
    this.getPicking(this.handler, viewer, calback, false);
  }
  removeByClick() {
    let viewer = this._viewer;
    const calback = (e:any) => {
      if(e.name =='Circle')viewer._entities.remove(e);
      else{ElMessage.error('当前点击的不是圆')}

      this.handler.destroy()

    };
    this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    this.getPicking(this.handler, viewer, calback, false);
  }
  getPicking(handler:any, viewer:any, callback:any, openTripParemeter:any) {
    // 创建一个ScreenSpaceEventHandler对象
    let _this = this;
    handler.setInputAction(function (click:any) {
      console.log("getPicking正在拾取坐标");
      var position = click.position;
      var pickedObject = viewer.scene.pick(position);
      // 检查pickedObject是否为实体
      if (
        Cesium.defined(pickedObject) &&
        Cesium.defined(pickedObject.id) &&
        pickedObject.id instanceof Cesium.Entity
      ) {
        // 获取点击的实体+
        var entity = pickedObject.id;
        // 输出实体信息
        const toolTip = pickedObject.id;
        _this.pickerEntity = entity;
        if (callback && typeof callback == "function") callback(entity);
        if (openTripParemeter && typeof openTripParemeter == "string")
          createRemindertip(entity[openTripParemeter], click.position, true);
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  }
}
